package com.bankwel.j3d.model;

import com.bankwel.j3d.core.J3dMatrix;
import com.bankwel.util.matrix.ArrayMatrix;
import com.bankwel.j3d.core.J3dChannel;

/**
 * 
 * @author Accelerator
 * @since 2015年12月9日 16:28:41
 *
 */
public class Vector3d {

	private float x;
	private float y;
	private float z;

	public Vector3d(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public Vector3d() {
		this.x = 0f;
		this.y = 0f;
		this.z = 0f;
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public float getZ() {
		return z;
	}

	public void setZ(float z) {
		this.z = z;
	}

	public Dot to2d() {
		return new Dot(x, y);
	}

	public Vector3d transform(J3dMatrix j3d) {
		float[][] v1 = { { x, y, z, 1 } };
		ArrayMatrix m = new ArrayMatrix(v1);
		float[][] v2 = m.times(j3d).toArray();
		if (v2 == null)
			return null;
		return new Vector3d(v2[0][0], v2[0][1], v2[0][2]);
	}

	public Vector3d add(float x, float y, float z) {
		return new Vector3d(this.x + x, this.y + y, this.z + z);
	}

	public static void main(String[] args) {
		Vector3d vec = new Vector3d(1, 1, 0);
		System.out.println(vec);
		long t1 = System.currentTimeMillis();
		for (int i = 0; i < 1000; i++)
			System.out.println(vec.transform(J3dChannel.rotateX((float) Math.PI / 2)));
		long t2 = System.currentTimeMillis();
		System.out.println("time:" + (t2 - t1));
	}

	@Override
	public String toString() {
		return "<" + (int) x + "," + (int) y + "," + (int) z + ">";
	}
}
